﻿using RazorEngine;
using RazorEngine.Templating; // For extension methods.
using ReportGen.Model;
using ReportGen.Read;
using System;
using System.Collections.Generic;
using System.IO;

namespace ReportGen
{
    /// <summary>
    /// text
    /// </summary>
    public class Help
    {
        public static string test1()
        {
            string template = "Hello @Model.Name, welcome to RazorEngine!";
            var result = Engine.Razor.RunCompile(template, "templateKey", null, new { Name = "World" });
            return result;
        }

        public static string test2()
        {
            string template = "Hello @Model.Name, welcome to RazorEngine!";
            var result = Engine.Razor.RunCompile(template, "templateKey", null, new { Name = "World" });
            result += Engine.Razor.Run("templateKey", null, new { Name = "Max" });
            return result;
        }

        public static string test3()
        {
            var path = AppDomain.CurrentDomain.BaseDirectory + "Templates\\UserInfo.cshtml";
            var template = File.ReadAllText(path);
            var model = new UserInfo { FirstName = "Bill", LastName = "Gates" };
            var result = Engine.Razor.RunCompile(template, "templateKey2", null, model);
            return result;
        }

        public static string xml1()
        {
            Person person = new Person()
            {
                Age = 25,
                Name = "陈超"
            };

            List<Cell> list = new List<Cell>();
            list.Add(new Cell() { Col = 0, Row = 0, ColSpan = 13, RowSpan = 0, Content = new CellContent() { ContentCDATA = "1" } });
            list.Add(new Cell() { Col = 1, Row = 1, ColSpan = 0, RowSpan = 0, Content = new CellContent() { ContentCDATA = "2" } });

            Report report = new Report()
            {
                Name = "sheet1",
                Class = "com.fr.report.worksheet.WorkSheet",
                CellElementList = new CellElementList { Cells = list },
                RowHeight = new RowHeight { DefaultValue = 723900, HeightContent = "1562100,1333500,1409700,723900,723900,723900,723900,723900,723900,723900,723900,723900" },
                ColumnWidth = new ColumnWidth { DefaultValue = 2743200, WidthContent = "2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200" },
            };

            WorkBook workBook = new WorkBook()
            {
                Report = report,
                ReleaseVersion = "20170715",
                XmlVersion = "8.0.0",
                DesignerVersion = new DesignerVersion { Version = "IAA" },
                PreviewType = new PreviewType(),
                TemplateID = new TemplateID { ID = Guid.NewGuid().ToString("N") },
            };

            var result = XmlConverter.Serialize<WorkBook>(workBook);
            return result;
        }

        public static string xml2()
        {
            var path = AppDomain.CurrentDomain.BaseDirectory + "Templates\\test.xml";
            var template = File.ReadAllText(path);

            WorkBook work = XmlConverter.Deserialize<WorkBook>(template);
            return work.ToString();
        }
    }
}